package com.ruoyi.web.controller.estate;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.estate.Parking;
import com.ruoyi.system.service.estate.IParkingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车位管理Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/estate/parking")
public class ParkingController extends BaseController
{
    @Autowired
    private IParkingService parkingService;

    /**
     * 查询车位列表
     */
    @PreAuthorize("@ss.hasPermi('estate:parking:list')")
    @GetMapping("/list")
    public TableDataInfo list(Parking parking)
    {
        startPage();
        List<Parking> list = parkingService.selectParkingList(parking);
        return getDataTable(list);
    }

    /**
     * 导出车位列表
     */
    @PreAuthorize("@ss.hasPermi('estate:parking:export')")
    @Log(title = "车位管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Parking parking)
    {
        List<Parking> list = parkingService.selectParkingList(parking);
        ExcelUtil<Parking> util = new ExcelUtil<Parking>(Parking.class);
        return util.exportExcel(list, "车位数据");
    }

    /**
     * 获取车位详细信息
     */
    @PreAuthorize("@ss.hasPermi('estate:parking:query')")
    @GetMapping(value = "/{parkingId}")
    public AjaxResult getInfo(@PathVariable("parkingId") Long parkingId)
    {
        return AjaxResult.success(parkingService.selectParkingById(parkingId));
    }

    /**
     * 新增车位
     */
    @PreAuthorize("@ss.hasPermi('estate:parking:add')")
    @Log(title = "车位管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Parking parking)
    {
        return toAjax(parkingService.insertParking(parking));
    }

    /**
     * 修改车位
     */
    @PreAuthorize("@ss.hasPermi('estate:parking:edit')")
    @Log(title = "车位管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Parking parking)
    {
        return toAjax(parkingService.updateParking(parking));
    }

    /**
     * 删除车位
     */
    @PreAuthorize("@ss.hasPermi('estate:parking:remove')")
    @Log(title = "车位管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{parkingIds}")
    public AjaxResult remove(@PathVariable Long[] parkingIds)
    {
        return toAjax(parkingService.deleteParkingByIds(parkingIds));
    }
} 